﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference name="Dimok.Web.UI.JS.JQuery.VSDoc.js" assembly="Dimok.Web.UI" />
/// <reference name="Dimok.Web.UI.JS.JSON_Lib.js" assembly="Dimok.Web.UI"/>
Type.registerNamespace("Dimok.Docks");

Dimok.Docks = function() {
  Dimok.Docks.initializeBase(this);
  this._initProps({_jqDocks: null});
}

Dimok.Docks.prototype = {
  DOCKS_SELECTOR: "table.Docks LI.ZoneAnchor",
  getDocksJson: function() {
    var docks = {};
    this.get_jqDocks().find(">LI:not(.ZoneAnchor)").each(function() {
      var parentProfileID = $J(this).parent()[0].profileID;
      docks[parentProfileID] = docks[parentProfileID] || [];
      docks[parentProfileID].push(this.profileID);
    });
    return docks;
  },
  _toggleEmpty: function(hide) {
    this.get_jqDocks().find("li.ZoneAnchor").each(function() {
      var me = $J(this);
      if (hide /*|| me.siblings("li").get().length > 0*/) me.hide();
      else {
        me.show().parent().append(me);
      }
    });
    //var td = $J("table.Docks"); if (hide) td.addClass("DocksHide"); else td.removeClass("DocksHide");
    return this;
  },

  initialize: function() {
    Dimok.Docks.callBaseMethod(this, 'initialize');
    this.set_jqDocks($J(this.DOCKS_SELECTOR).parent().sortable({
      connectWith: ["table.Docks UL"],
      handle: "LEGEND",
      //dropOnEmpty: true,
      //delay: 500,
      //distance: 5,
      revert: false,
      tolerance: "pointer",
      forcePlaceholderSize: false,
      start: Function.createCallback(function(e, ui, context) { context._toggleEmpty(); $J(this).sortable("refresh"); }, this),
      stop: Function.createDelegate(this, function() { this._toggleEmpty(true); })
    }));
    //this._toggleEmpty();
  },
  dispose: function() {
    Dimok.Docks.callBaseMethod(this, 'dispose');
  }
}
Dimok.Docks.registerClass('Dimok.Docks', motobankcorp.Component);

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
